<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑用户 - 控制面板</title>
    <link rel="stylesheet" href="/css/style.css">
    <style>
        .user-profile-image {
            width: 150px;
            height: 150px;
            border-radius: 50%;
            object-fit: cover;
            border: 3px solid var(--primary-color);
            padding: 3px;
            margin-bottom: 20px;
        }
        .profile-image-container {
            text-align: center;
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
    <div class="dashboard-container">
        <div class="sidebar">
            <div class="sidebar-header">
                <h2>控制面板</h2>
            </div>
            <ul class="sidebar-menu">
                <li><a href="/dashboard">主页</a></li>
                <li><a href="/dashboard/profile">个人信息</a></li>
                <li><a href="/dashboard/change-password">修改密码</a></li>
                <li><a href="/dashboard/documents">文档管理</a></li>
                <li><a href="/dashboard/categories">分类管理</a></li>
                <li><a href="/dashboard/weblinks">网站链接管理</a></li>
                <li class="active"><a href="/dashboard/users">用户管理</a></li>
                <li><a href="/dashboard/settings">网站设置</a></li>
                <li><a href="/danmaku-display">弹幕墙</a></li>
                <li><a href="/weblinks" target="_blank">网站导航</a></li>
                <li><a href="/" target="_blank">访问首页</a></li>
                <li><a href="/logout">退出登录</a></li>
            </ul>
        </div>
        
        <div class="main-content">
            <div class="dashboard-header">
                <div class="dashboard-title">
                    <h1>编辑用户</h1>
                </div>
            </div>
            
            <div class="alert alert-success" th:if="${successMessage}">
                <p th:text="${successMessage}"></p>
            </div>
            
            <div class="alert alert-danger" th:if="${errorMessage}">
                <p th:text="${errorMessage}"></p>
            </div>
            
            <div class="card">
                <div class="card-header">
                    <h2>修改用户信息</h2>
                </div>
                <div class="card-body">
                    <form th:action="@{/dashboard/users/edit/{id}(id=${user.id})}" method="post" th:object="${user}" enctype="multipart/form-data">
                        <div class="profile-image-container">
                            <img th:src="${user.profileImage != null ? user.profileImage : '/images/default-avatar.svg'}" 
                                 alt="用户头像" class="user-profile-image">
                            <div>
                                <input type="file" id="profileImageFile" name="profileImageFile" accept="image/*">
                                <small>选择一张新头像（可选）</small>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label for="username">用户名</label>
                            <input type="text" id="username" name="username" th:field="*{username}" class="form-control" readonly>
                            <small class="form-text text-muted">用户名不可修改</small>
                        </div>
                        
                        <div class="form-group">
                            <label for="email">电子邮箱</label>
                            <input type="email" id="email" name="email" th:field="*{email}" class="form-control" required>
                        </div>
                        
                        <div class="form-group">
                            <label for="fullName">姓名</label>
                            <input type="text" id="fullName" name="fullName" th:field="*{fullName}" class="form-control">
                        </div>
                        
                        <div class="form-group">
                            <label for="role">角色</label>
                            <select id="role" name="role" th:field="*{role}" class="form-control" required>
                                <option value="USER">普通用户</option>
                                <option value="EDITOR">编辑</option>
                                <option value="ADMIN">管理员</option>
                            </select>
                        </div>
                        
                        <div class="form-group">
                            <div class="form-check">
                                <input type="checkbox" id="enabled" name="enabled" th:field="*{enabled}" class="form-check-input">
                                <label for="enabled" class="form-check-label">启用账户</label>
                            </div>
                        </div>
                        
                        <div class="form-actions">
                            <button type="submit" class="btn btn-primary">保存修改</button>
                            <a th:href="@{/dashboard/users}" class="btn btn-secondary">返回列表</a>
                        </div>
                    </form>
                </div>
            </div>
            
            <div class="card mt-4">
                <div class="card-header">
                    <h2>用户活动</h2>
                </div>
                <div class="card-body">
                    <div class="table-responsive" th:if="${!userActivities.empty}">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th>时间</th>
                                    <th>活动类型</th>
                                    <th>详情</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr th:each="activity : ${userActivities}">
                                    <td th:text="${#temporals.format(activity.createdAt, 'yyyy-MM-dd HH:mm')}"></td>
                                    <td th:text="${activity.type}"></td>
                                    <td th:text="${activity.description}"></td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div th:if="${userActivities.empty}" class="alert alert-info">
                        <p>没有记录用户活动。</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script src="/js/script.js"></script>
</body>
</html> 